<?php
namespace Weblog\Http\Controllers;

use Overtrue\Socialite\SocialiteManager;
/**
* 
*/
class MemberController extends Controller
{
	public function auth()
	{
		$config = [
			'weibo' => [
				'client_id'     => '2547489686',
				'client_secret' => '83cfd1bcfde171dcfa65db8024dc658d',
				'redirect'      => 'http://www.wb.com/member/callback',
			],
		];

		$socialite = new SocialiteManager($config);

		$response = $socialite->driver('weibo')->redirect();
		// $response = $withRedirectUrl->driver('weibo');

		echo $response;// or $response->send();
	}

	public function callback()
	{
		$config = [
			'weibo' => [
				'client_id'     => '2547489686',
				'client_secret' => '83cfd1bcfde171dcfa65db8024dc658d',
				'redirect'      => 'http://www.wb.com/member/callback',
			],
		];

		$socialite = new SocialiteManager($config);
		$user = $socialite->driver('weibo')->user();
		var_dump(json_encode($user));
		var_dump($user->getToken());
		exit;

		$user->getId();        // 1472352
		$user->getNickname();  // "overtrue"
		$user->getName();      // "安正超"
		$user->getEmail();     // "anzhengchao@gmail.com"
		$user->getProviderName(); // GitHub;
	}
	/**
	 * Get the login username to be used by the controller.
	 *
	 * @return string
	 */
	public function loginUsername()
	{
		return property_exists($this, 'username') ? $this->username : 'email';
	}
}